package com.sa07.utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 日期工具类
 * 
 * @author Long.shangbo
 *
 * 2014-2-17 下午9:51:03
 */
public class DateUtils {
	
	private static ThreadLocal<SimpleDateFormat> dateFormatLocal = new ThreadLocal<SimpleDateFormat>();
	
	private static final String SIMPLE_FORMAT_PATTERN = "yyyy-MM-dd HH:mm:SSS";
	
	/**
	 * 获得日期格式化对象
	 * @return
	 */
	private static DateFormat getDefaultDateFormat(){
		SimpleDateFormat dateFormat = dateFormatLocal.get();
		
		if(dateFormat == null){
			dateFormat = new SimpleDateFormat(SIMPLE_FORMAT_PATTERN);
			dateFormatLocal.set(dateFormat);
		}
		
		return dateFormat;
	}
	
	/**
	 * 使用默认格式格式化日期
	 * @return
	 */
	public static String formatWithDefaultPattern(Date date){
		return getDefaultDateFormat().format(date);
		
	}
}
